﻿using MeetAI.Utility.Table;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace MeetAI.Repository.IRepository
{
	public partial interface IBaseRepository<T>
	{
		/// <summary>
		/// 根据主值查询单条数据
		/// </summary>
		/// <param name="pkValue">主键值</param>
		/// <returns>泛型实体</returns>
		Task<T> FindByIdAsync(object pkValue);

		/// <summary>
		/// 表达式获取单条数据
		/// </summary>
		/// <param name="predicate"></param>
		/// <returns></returns>

		Task<T> FindAsync(Expression<Func<T, bool>> predicate);

		/// <summary>
		/// 查询所有数据(无分页,请慎用)
		/// </summary>
		/// <returns></returns>
		Task<IEnumerable<T>> FindAllAsync();
		/// <summary>
		/// 根据条件查询数据
		/// </summary>
		/// <param name="predicate">条件表达式树</param>
		/// <param name="orderBy">排序</param>
		/// <returns>泛型实体集合</returns>
		Task<IEnumerable<T>> FindListByClauseAsync(Expression<Func<T, bool>> predicate, string orderBy = "");
		/// <summary>
		/// 
		/// </summary>
		/// <param name="predicate"></param>
		/// <param name="orderBy"></param>
		/// <param name="pageIndex"></param>
		/// <param name="pageSize"></param>
		/// <returns></returns>
		Task<IEnumerable<T>> FindListNoTotalByClauseAsync(Expression<Func<T, bool>> predicate, string orderBy = "", int pageIndex = 1, int pageSize = 20);

		/// <summary>
		/// 根据条件查询数据
		/// </summary>
		/// <param name="predicate">条件表达式树</param>
		/// <returns></returns>
		Task<T> FindByClauseAsync(Expression<Func<T, bool>> predicate);

		/// <summary>
		/// 写入实体数据
		/// </summary>
		/// <param name="entity">实体类</param>
		/// <returns></returns>
		Task<long> InsertAsync(T entity);

		/// <summary>
		/// 
		/// </summary>
		/// <param name="entity"></param>
		/// <returns></returns>
		Task<int> InsertCommandAsync(T entity);
		/// <summary>
		/// 更新实体数据
		/// </summary>
		/// <param name="entity"></param>
		/// <returns></returns>
		Task<bool> UpdateAsync(T entity);

		/// <summary>
		/// 删除数据
		/// </summary>
		/// <param name="entity">实体类</param>
		/// <returns></returns>
		Task<bool> DeleteAsync(T entity);
		/// <summary>
		/// 删除数据
		/// </summary>
		/// <param name="where">过滤条件</param>
		/// <returns></returns>
		Task<bool> DeleteAsync(Expression<Func<T, bool>> @where);

		/// <summary>
		/// 删除指定ID的数据
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		Task<bool> DeleteByIdAsync(object id);

		/// <summary>
		/// 删除指定ID集合的数据(批量删除)
		/// </summary>
		/// <param name="ids"></param>
		/// <returns></returns>
		Task<bool> DeleteByIdsAsync(object[] ids);

		/// <summary>
		/// 根据条件查询分页数据
		/// </summary>
		/// <param name="predicate"></param>
		/// <param name="orderBy"></param>
		/// <param name="pageIndex">当前页面索引</param>
		/// <param name="pageSize">分布大小</param>
		/// <returns></returns>
		Task<IPagedList<T>> FindPagedListAsync(Expression<Func<T, bool>> predicate, string orderBy = "", int pageIndex = 1, int pageSize = 20);
	}
}
